package com.gist.cithub.service.service.impl;

import com.gist.cithub.service.entity.StarEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gist.common.utils.PageUtils;
import com.gist.common.utils.Query;

import com.gist.cithub.service.dao.ValuateDao;
import com.gist.cithub.service.entity.ValuateEntity;
import com.gist.cithub.service.service.ValuateService;


@Service("valuateService")
public class ValuateServiceImpl extends ServiceImpl<ValuateDao, ValuateEntity> implements ValuateService {
   @Autowired
   ValuateDao valuateDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ValuateEntity> page = this.page(
                new Query<ValuateEntity>().getPage(params),
                new QueryWrapper<ValuateEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public ValuateEntity getUserScore(Integer serviceId, Integer userId) {
        QueryWrapper<ValuateEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.and(
                wrapper ->
                        wrapper.eq("service_id", serviceId).eq("user_id",userId)
        );
        ValuateEntity res= valuateDao.selectOne(queryWrapper);
        return res;
    }

}